package com.server.questionbank.snframe.controller;

import com.server.questionbank.snframe.domain.ResDTO.ResponseResult;
import com.server.questionbank.snframe.util.MinIo.ProgressInputStream;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/transmissionProgress")
public class TransmissionProgress {
    @Autowired
    private StringRedisTemplate redisTemplate;

    // 获取传输进度
    @PostMapping("/getProgress")
    public ResponseResult<Float> getProgress(@RequestBody Map<String, String> map) {
        if (map.get("sessionId") == null) return ResponseResult.error("sessionId不能为空");
        return ResponseResult.success(ProgressInputStream.getProgress(redisTemplate, map.get("sessionId")));
    }
}
